$(function(){

    $('.doubledate').kuiDate({
        className: 'doubledate',
        isDisabled: "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
    });
    //initImage()

});
$(function(){
    $("#shopIsChoosed").click(function(){
        if ($("#shopIsChoosed").is(":checked")) {
            $("#shopName").attr("disabled", false);
            $("#research").attr("disabled", false);
            
        }
        else {
            $("#shopName").attr("disabled", true);
            
        }
    });
})
function downRescouse(){
    var mp = $("#mp").val().replace(/\s/gi, '');
    var name = $("#name").val().replace(/\s/gi, '');
    var type = $("#type").val();
    var dtBegin = $("#dtBegin").val();
    var dtEnd = $("#dtEnd").val();
    var shopId = "";
    if ($("#shopIsChoosed").is(":checked")) {
        shopId = $("#shopName").val();
        if (shopId != "" && shopId != null) {
        
        }
        else {
            shopId = "";
        }
    }
    
    var params = {
        'mp': mp,
        'name': name,
        'type': type,
        'dtBegin': dtBegin,
        'dtEnd': dtEnd,
        'shopId': shopId
    }
    window.location.href = "../apply/export/csv?" + $.param(params);
    
}

function deleteInfo(id){

    $.post("../shop/del/deleteShop", {
        "id": id
    }, function(data){
        var dt = JSON.parse(data);
        if (IsEmpty(dt)) {
            art.dialog({
                fixed: true,
                lock: true,
                content: "删除出错",
                icon: 'error',
                ok: true
            });
            return false;
        }
        if (dt.state == 0) {
            InitTable();
            art.dialog({
                fixed: true,
                lock: true,
                content: "删除成功",
                icon: 'succeed',
                ok: true
            });
        }
        else 
            if (dt.state == 1) {
                art.dialog({
                    fixed: true,
                    lock: true,
                    content: dt.msg,
                    icon: 'error',
                    ok: true
                });
            }
            else {
                checkStateShowErrorMsgAndDealResult(data);
            }
    });
    
}

function popPoint(id){
    art.dialog({
        fixed: true,
        lock: true,
        content: "确认删除该条数据？",
        icon: 'question',
        ok: function(){
            deleteInfo(id)
        },
        cancel: true
    });
}

function searchApply(){
    getTryDriverList(1);
}

function getTryDriverList(index){
    if (IsEmpty(index)) {
        index = 1
    }
    
    var mp = $("#mp").val().replace(/\s/gi, '');
    var name = $("#name").val().replace(/\s/gi, '');
    var type = $("#type").val();
    var dtBegin = $("#dtBegin").val();
    var dtEnd = $("#dtEnd").val();
    var shopId = "";
    if ($("#shopIsChoosed").is(":checked")) {
        shopId = $("#shopName").val();
        if (shopId != "" && shopId != null) {
        
        }
        else {
            shopId = "";
        }
    }
    
    var params = {
        'mp': mp,
        'name': name,
        'type': type,
        'dtBegin': dtBegin,
        'dtEnd': dtEnd,
        'shopId': shopId
    }
    var dt = _findInfo("../apply/find/applyList/" + (index - 1) + "/10", params);
    if (IsNotEmpty(dt) && dt.state == 0) {
        $("#memberList tbody").empty()
        
        for (var i = 0; i < dt.result.data.length; i++) {
            var htm = "<tr>"
            htm += "<td>" + _getStringOfJson(i, dt, "type") + "</td>"
            htm += "<td> <img src='" + _getStringOfJson(i, dt, "imageUrl") +
            "' onclick=\"openImage(\'" +
            _getStringOfJson(i, dt, "imageUrl") +
            "\')\" ></td>"
            htm += "<td>" + _getStringOfJson(i, dt, "name") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "mp") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "IDNumber") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "age") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "address") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "Nation") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "qq") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "staName") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "height") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "weight") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "love") + "</td>"
            htm += "<td>" + _getStringOfJson(i, dt, "createdTime") +
            "</td>"
            var id = _getIntOfJson(i, dt, "id")
            htm += "<td> <input type='button' class='common_btn' value='设置' class='btn' onclick='setting(" +
            id +
            ")'></td>"
            htm += "</tr>"
            $("#memberList tbody").append(htm)
        }
        /* 		_loadInfo(dt, "memberList", param)
         */
        $("#memberList tbody tr").each(function(){
        
        })
        _loadPage("pager", index, 10, dt, getTryDriverList, "NoResult");
        $("#sup").html("共" + dt.result.len + "条");
    }
}

//改变女主播
function setting(id){
    var url = " ../apply/find/applyById";
    $("#upid").val(id);
    if (id > 0) {
        $.get(url, {
            "id": id
        }, function(g){
            var rst = JSON.parse(g);
            console.log(rst);
            $("#Name").val(_getStringOfJson(0, rst, 'name'))
        });
        
        $("#window_change").show();
        addMargin($("#window_change"));
        
    }
}

function updateApply(){
    var upid = $("#upid").val();
    var uname = $("#Name").val();
    var heads = new Array("name", "id");
    var datas = new Array(uname, id);
    var parser = new Object();
    
    var jsonParserStr = null;//定义空头字符串
    if (IsNotEmpty(datas)) {
        addToParser(heads, datas, "edit", parser);
        jsonParserStr = JSON.stringify(parser);
    }
    
    var url = " ../apply/up/updateApplyId";
    $.post(url, {
        "data": jsonParserStr
    }, function(data){
        $("#close_this").attr("disabled", false);
        var dt = JSON.parse(data);
    });
}

function initImage(){
    Shadowbox.init();
    window.openImage = function(url){
        Shadowbox.open({
            content: url,
            player: 'img'
        });
    };
}

